/**
	Broadcaster class,
	@author Ashley Holtgraver
	@version 2006-01-18

* @usage:
*  in class constructor of listening class,
*  Broadcaster.getBroadcaster().addEventListener("functionName", this);
*
*  in functon with item to be broadcasted to,
*  function functionName(evt:Object) : Void {
*		var myreceivedvar = evt.varname;
*	}
*
*---------------------------------------------------
*  in class you want to broadcast from,
*    private var broadcast:Broadcaster
*
*  in function with the item to be broadcasted:
*  function sendOutVar(){
*		var whatisend = ...
*		broadcaster.broadcast("functionName", {varname: whatisend});
*  }
*
**/


class timber.util.Broadcaster
{
 	private static var instance:Broadcaster;

	private function Broadcaster()
	{
		mx.events.EventDispatcher.initialize(this);
	}

	/** Returns your Broadcaster instance.
	* @return	your single Broadcaster instance
	*/
	public static function getBroadcaster(Void):Broadcaster
	{
		if (!instance)
		{
			instance = new Broadcaster();
		}
		return instance;
	}

 	// we have to declare the dispatchEvent,
 	// addEventListener and removeEventListener
 	// methods that EventDispatcher sets up:
 	public function dispatchEvent(eventObject:Object) : Void {};
 	public function addEventListener(eventName:String, handlerObjectOrMethod:Object) : Void {};
 	public function removeEventListener(handler:Function) : Void {};

	/** function called to broadcast out an event and object(s)
	* @param eventName  name of previously added listening event
	* @param args  object(s) to be dispatched to listener
	*/
 	public function broadcast(eventName:String, args:Object) : Void
 	{
 		if (!args) args = {};
 		args["type"] = eventName;
 		dispatchEvent(args);
 	}
 	
}